
JavaScript have some pre define method to sort the array my ascending or descending. We also called up to bottom sort or bottom to up sort. This pre defend method very helpful to sort the JavaScript array. We also use reverse method to reverse the array or collection. If we don’t have use the function then the code more than complexes because we write the code explicitly. Now given bellow the example code and explain the code:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
var human = ["Reza", "Jesy", "Tofile", "Dipto"];
console.log(human);
function myFunction() {
human.sort();
console.log(human);
}
myFunction();
</script>
</body>
</html>
Now we can see the sort value of the array by using JavaScript sort method. If we work same but doesn’t use the method it will be more complex code. So, this type function is responsible to code are easier.